<%@ include file="../import_page.jsp" %>
<%
	//login checking
	if(loginedChecking(session, UsersType.admin)) {
		//user logined
	}
	else
	{
		//user don't login
		//redirect to home page
		response.sendRedirect(URL_HOMEPAGE);
	}
	
	String msg = "";
	//POST back check
	if(request.getMethod() == "POST") {
		//validate input
		String unitName = request.getParameter("unit_name");
		String unitId = request.getParameter("unit_id");
		if(!(isEmptyString(unitName) || isEmptyString(unitId))) {
			//start creat unit process
			try {
				UnitsControl unitCon = new UnitsControl();
				unitCon.createUnit(new Units(unitId, unitName));
				unitCon.closeDBConnection();
				msg = "Units: "+ unitName+ " ("+ unitId+ ") Create success";
			} catch (Exception err) {
				msg = err.toString();
			}
		}
	}
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login</title>
<style type="text/css">
<!--
.style1 {
	font-size: large;
	font-weight: bold;
	text-align: center;
}
.style3 {
	font-size: large;
	text-align: center;
}
-->
</style>
</head>

<body>
<form id="creat_unit_form" name="creat_unit_form" method="post" action="create_new_unit.jsp">
<table width="500" height="268" border="1" bordercolor="#CCCCCC" bgcolor="#00FF99">
  <tr>
    <td height="63" colspan="2"><span class="style1">Create New Unit</span></td>
  </tr>
  <tr>
    <td width="53" height="63"><span class="style3">Unit Name </span></td>
    <td width="296">
        <input name="unit_name" type="text" id="unit_name" />
    </td>
  </tr>
  <tr>
    <td height="65"><span class="style3">Unit Code </span></td>
    <td><input name="unit_id" type="text" id="unit_id" /></td>
  </tr>
  <tr>
    <td height="65" colspan="2">
      <span class="style3"><input type="submit" name="Submit" value="Submit" /></span>
    </td>
  </tr>
</table>
</form>
<p align="center"><%= msg.isEmpty() ? "&nbsp;" : msg %></p>
</body>
</html>
